import 'dart:math';

import 'package:flutter_taotaoshipin/app/app_controller.dart';
import 'package:get/get.dart';

/// 数字转万，亿
String countFormat(int count) {
  String res = '';
  if (count > 9999) {
    res = '${(count / 10000).toStringAsFixed(2)}万';
  } else {
    res = count.toString();
  }
  return res;
}

bool isVip() {
  bool result = false;
  AppController controller = Get.find();
  if (controller.userinfoCenterEntity.plusExpire != null) {
    // vip过期时间大于当前时间
    if (controller.userinfoCenterEntity.plusExpire! * 1000 >
        DateTime.now().millisecondsSinceEpoch) {
      result = true;
    }
  }
  return result;
}

bool showNativeAd() {
  return false;
  // bool res = false;
  // AppController appController = Get.find();
  // var nativeAd = appController.csj.list
  //     ?.firstWhereOrNull((element) => element.adverType == '3');
  // if (nativeAd == null || isVip()) {
  //   res = false;
  // } else {
  //   res = true;
  // }
  // return res;
}

int randomGen(int min, int max) {
  var x = Random().nextInt(max) + min;
  return x.floor();
}

int randomReadCount() {
  return randomGen(3000, 20000);
}

/// 7天=周
String daysToCycleTime(int days) {
  var each = '$days天';
  if (days == 7) {
    each = '周';
  } else if (days == 30) {
    each = '月';
  } else if (days == 31) {
    each = '月';
  } else if (days == 90) {
    each = '季';
  } else if (days == 180) {
    each = '半年';
  } else if (days == 360) {
    each = '年';
  } else if (days == 365) {
    each = '年';
  }
  return each;
}
